<template>
  <div v-show="header.ifshow">
    <div class="ub headerDiv ub-ac">
      <div class="ub left ub-pc" @click='backClc'>
        <div class="ub-img1" :class="header.leftIcon" v-if="header.leftIcon"></div>
        <div v-if="header" class="header-left">{{header.left}}</div>
      </div>
      <div class="ub middle ub-pc">
        <div class="tx-c fz12">
          {{header.middle}}
        </div>

      </div>
      <div class="ub right ub-pc" @click='rightClc'>
        <div v-if="header.right">
          {{header.right}}
        </div>
        <div class="ub-img" :class="header.rightIcon" v-if="header.rightIcon"></div>
      </div>
    </div>
    <div class="posDiv"></div>
  </div>
</template>
<script type="text/ecmascript-6">
const checkPath = {
  '/home': true,
  // '/login': true,
  '/': true
};
export default {
  name: 'headers',
  props: {
    header: {
      type: Object
    }
  },
  methods: {
    backClc: function () {
      // console.log('back');
      // console.log(this.header);
      // console.log(this.$router.history.current.fullPath)
      let currentPath = this.$router.history.current.fullPath;
      console.log('this is' + currentPath)
      if (checkPath[currentPath]) {
        console.log(currentPath + '设置为不能再退');
        // this.$router.push('/home');
        return false;
      }
      let left = this.header.leftAction;
      if (!left) {
        return false;
      } else if (left === '-1') {
        this.$router.go(-1);
      } else {
        console.log(left);
        this.$router.push(left);
      }
    },
    rightClc: function () {
      // console.log('rightClc');
      let right = this.header.rightAction;
      if (!right) {
        return false;
      } else if (right === '-1') {
        this.$router.go(-1);
      } else {
        if (right === '/home') {
          right = '/index'
        }
        this.$router.push(right);
      }
    }
  }
}
</script>


<style lang="stylus">
@import '../../stylus/base.styl';
.headerDiv
  font-size: $fontSize;
  width: 100%;
  height: f_times(2.5);
  background-color: #843d99;
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
.posDiv
  height: f_times(2.5);
  z-index: -1;
.left, .right
  width: 20%;
.middle
  width: 100% - f_times(2.5);
.leftIcon
  height: $fontSize;
  width: $fontSize;
  background-image: url('');
.closeIcon
  height: $fontSize;
  width: $fontSize;
  background-image: url('nav_close@2x.png');
.homeIcon
  height: f_times(1.8);
  width: f_times(1.8);
  background-image: url('nav_home_white@2x.png');
</style>